/**
 * 
 * @author Huang Junjie
 *
 */

package TimeSqueeze.storage;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

import TimeSqueeze.common.TaskInterface;

public class TempStorage {
	
    public static ArrayList<TaskInterface> untimedTasks = new ArrayList<TaskInterface>();
    public static ArrayList<TaskInterface> deadlineTasks = new ArrayList<TaskInterface>();
    public static ArrayList<TaskInterface> timedTasks = new ArrayList<TaskInterface>();
    
    public static void addToUntimed(TaskInterface toBeAdded) {
        untimedTasks.add(toBeAdded);
    }
    
    public static void addToDeadline(TaskInterface toBeAdded) {
        deadlineTasks.add(toBeAdded);
    }
    
    public static void addToTimed(TaskInterface toBeAdded) {
        timedTasks.add(toBeAdded);
    }
    
    public static void deleteFromUntimed(int index) {
    	untimedTasks.remove(index);
    }
    
    public static void deleteFromDeadline(int index) {
    	deadlineTasks.remove(index);
    }
    
    public static void deleteFromTimed(int index) {
    	timedTasks.remove(index);
    }
    
    public static void clearUntimed() {
    	untimedTasks.clear();
    }
    
    public static void clearDeadline() {
    	deadlineTasks.clear();
    }
    
    public static void clearTimed() {
    	timedTasks.clear();
    }
    
    public static void readFileToProgMem() throws IOException {
    	ReadFromFile fileIn = new ReadFromFile();
    	fileIn.readFileToMem(untimedTasks, deadlineTasks, timedTasks);
    }
    
    public static void updateFile() {
    	WriteToFile updator = new WriteToFile(untimedTasks,deadlineTasks,timedTasks);
    	try {
			updator.saveToFile();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println("Save file not found. Data cannot be permanently saved.");
		}
    }

}